package com.wenli.graduate2022.wenliGreenShop.controller;

import com.wenli.graduate2022.wenliGreenShop.entity.ProductOrderItem;
import com.wenli.graduate2022.wenliGreenShop.service.servDao.ProductOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author HuangHai
 * @date 2021/10/13 16:42
 */
@RestController
public class ProductOrderItemController {

    @Autowired
    ProductOrderItemService productOrderItemService;


    @GetMapping("/productOrderItem/findByProductId/{productId}")
    public List<ProductOrderItem> findByProductId(@PathVariable("productId") Integer productId) { //根据产品id查询所有产品订单，可以用于查询该产品已经销售了多少件
        return productOrderItemService.findByProductId(productId);
    }

    @GetMapping("/productOrderItem/findByOrderId/{id}")
    public List<ProductOrderItem> findByOrderId(@PathVariable("id")Integer id) {    // 根据订单id查询该订单下的所有产品订单
        return productOrderItemService.findByOrderId(id);
    }

    @GetMapping("/productOrderItem/findById/{id}")
    public ProductOrderItem findById(@PathVariable("id")Integer id) {      //根据id查询产品订单
        return productOrderItemService.findById(id);
    }

    @GetMapping("/productOrderItem/findByUserId/{id}")
    public List<ProductOrderItem> findByUserId(@PathVariable("id")Integer id) {       //根据用户id查询该用户下的所有产品订单
        return productOrderItemService.findByUserId(id);
    }


}
